import serial
import time

time1 = time.clock()

time.sleep(1)
# print time.clock() - time1
ser = serial.Serial('COM17', 9600, timeout=1)
xavg = 0
yavg = 0
zavg = 0
counter = 0

currentX 	= 0
currentY 	= 0
currentZ 	= 0
initX 		= 0
initY 		= 0
initZ 		= 0
inittimer 	= 30 # WAIT 10 SEC TO GET INITIAL POSITION
initcounter = 0

while (time.clock() - time1) < inittimer:
	line = ser.readline()
	array = line.split(',')
	if len(array) > 16:
		print array[0] ,array[9], array[10],array[13],array[14],array[15]
		initX = (initX*counter + float(array[13]))/(counter + 1)
		yavg = (yavg*counter + float(array[14]))/(counter + 1)
		zavg = (zavg*counter + float(array[15]))/(counter + 1)
		counter = counter + 1
	else: 
		print line


		